/**
 * 校验链接协议
 * @param {string} path
 * @returns {Boolean}
 */
function isExternalFn(path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}

/**
 * 校验链接地址
 * @param {string} url
 * @returns {Boolean}
 */
function validURLFn(url) {
  const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
  return reg.test(url)
}

/**
 * 校验邮箱
 * @param {string} email
 * @returns {Boolean}
 */
function validEmailFn(email) {
  const reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
  return reg.test(email)
}

/**
 * 校验身份证号码
 * @param {string} IdCard
 * @returns {Boolean}
 */
function validIdCardFn(IdCard) {
  const reg = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/g
  return reg.test(IdCard)
}

/**
 * 校验手机号码
 * @param {string} validPhone
 * @returns {Boolean}
 */
function validPhoneFn(phone) {
  const reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/g
  return reg.test(phone)
}

/**
 * 校验统一社会信用代码
 * @param {string} creditCard
 * @returns {Boolean}
 */
function validCreditCardFn(creditCard) {
  const reg = /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/g
  return reg.test(creditCard)
}

/**
 * 校验中文正则
 * @param {string} str
 * @returns {Boolean}
 */
function validChineseFn(str) {
  const reg = /[\u4E00-\u9FA5]/g
  return reg.test(str)
}

/**
 * 校验密码强度正则
 * 密码中必须包含字母、数字、特称字符，至少8个字符，最多30个字符
 * @param {string} password
 * @returns {Boolean}
 */
function validPasswordFn(password) {
  const reg = /(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,30}/g
  return reg.test(password)
}

export default {
  isExternalFn,
  validURLFn,
  validEmailFn,
  validIdCardFn,
  validPhoneFn,
  validCreditCardFn,
  validChineseFn,
  validPasswordFn
}